﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace Jurassic_Island
{
    public class CADObjetoFinal
    {
        static private String cadenaConexion = ConfigurationManager.ConnectionStrings["JurassicBDConnectionString"].ConnectionString;
        static private String nombreTabla = "Objetos_Finales";

        public DataSet ObtenerTablaObjetoFinal()
        {
            DataSet dsObjetoFinal = new DataSet();

            try
            {
                SqlConnection conexion = new SqlConnection(cadenaConexion);
                String consulta = "Select * from Objetos_Finales";
                SqlDataAdapter daObjetoFinal = new SqlDataAdapter(consulta, conexion);
                daObjetoFinal.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                daObjetoFinal.Fill(dsObjetoFinal, nombreTabla);
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            return dsObjetoFinal;
        }

        public bool ActualizarObjetosFinal(DataSet dsObjetosFinal)
        {
            bool resultado = false;

            try
            {
                SqlConnection conexion = new SqlConnection(cadenaConexion);
                String consulta = "Select * from Objetos_Finales";
                SqlDataAdapter daObjetoFinal = new SqlDataAdapter(consulta, conexion);
                SqlCommandBuilder cb = new SqlCommandBuilder(daObjetoFinal);
                //cb.ConflictOption = ConflictOption.OverwriteChanges;
                //daPartida.UpdateCommand = cb.GetUpdateCommand();
                daObjetoFinal.Update(dsObjetosFinal, nombreTabla);
                dsObjetosFinal.Tables[nombreTabla].AcceptChanges();

                resultado = true;
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            return resultado;
        }

        public DataSet ObtenerObjetosFinalPorFinal(string NombreFinal)
        {
            DataSet dsObjetoFinal = new DataSet();

            try
            {
                SqlConnection conexion = new SqlConnection(cadenaConexion);
                String consulta = "Select * from Objetos_finales where nombrefinal_objfin='" + NombreFinal + "'";
                SqlDataAdapter daObjetoFinal = new SqlDataAdapter(consulta, conexion);
                daObjetoFinal.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                daObjetoFinal.Fill(dsObjetoFinal, nombreTabla);
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            return dsObjetoFinal;
        }
    }
}
